<?php

define('IN_API', true);
require_once '../../framework/bootstrap.inc.php';
require_once 'defines.php';
$id = $_GPC['id'];
$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" => $id));
$settings = unserialize($settings['settings']);

$now_time = time();
if(intval($_GPC['t']) == 3){
	$addtime = 3*3600;
}else{
	$addtime = 1200;
}
if(intval($_GPC['sh']) > 0){
	$sh = intval($_GPC['sh']);
}else{
	$sh = 0;
}
if(intval($_GPC['h']) > 0){
	$h = intval($_GPC['h']);
}else{
	$h = 24;
}
if(intval($_GPC['d']) > 0){
	$start_timeStamp = strtotime(date('Y-m-d',time()) . " -".intval($_GPC['d']-1)." day") + $sh*3600;
	$end_timeStamp = $start_timeStamp + $h*3600;
	$start_time = date('Y-m-d H:i:s',$start_timeStamp);
    $end_time = $start_time + $addtime;
}else{
	$start_timeStamp = $now_time - $addtime;
    $end_timeStamp = $now_time;
	$start_time = date('Y-m-d H:i:s',$start_timeStamp);
    $end_time = date('Y-m-d H:i:s',$end_timeStamp);
}


do {
    sleep(1);
    $stime = $start_timeStamp;
	$end_time = date('Y-m-d H:i:s',$stime + $addtime);
	$start_time = date('Y-m-d H:i:s',$stime);
	echo $start_time.'|'.$end_time.'<br/>';
	
	$res = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_dingdanchaxun2.ashx?appkey='.$settings['appkey'].'&sid='.$_GPC['sid'].'&start_time='.urlencode($start_time).'&end_time='.urlencode($end_time).'&signurl=2&query_type='.$_GPC['query_type'].'&order_scene='.$_GPC['order_scene']),true);
	$res = json_decode(file_get_contents($res['url']),true);
	$res_data = $res['tbk_sc_order_details_get_response']['data']['results']['publisher_order_dto'];
	$position_index = $res['tbk_sc_order_details_get_response']['data']['position_index'];
	$has_next = $res['tbk_sc_order_details_get_response']['data']['has_next'];

	if($res_data){
		foreach ($res_data as $k => $v) {
			if(strpos($settings['pid_black'],$v['site_id'].'_'.$v['adzone_id']) !== false){ 
			    continue;
			}
			if($v['site_id'].'_'.$v['adzone_id']){}
			if($v['order_type'] == '饿了么'){
				if($settings['system_type'] == 1){
					$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => trim($v['trade_parent_id']), "system_id" => $settings['system_id']));
					if($order){
						if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
						$fee = fee($order['c_1_uid'],$id);
						if($settings['errorcodeid'] == 91){
							var_dump($fee);
						}
						if($v['tk_status'] == 3){
							pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "tk_earning_time" => strtotime($v['tk_earning_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'], "system_id" => $settings['system_id'] , "c_1" => round($v['pub_share_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "system_id" => $settings['system_id']));
						}else{
							if($v['tk_status'] == 13){$v['pub_share_pre_fee'] = 0;}
							pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'], "system_id" => $settings['system_id'] , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "system_id" => $settings['system_id']));
						}
						
					}else{
						//是否有渠道id，有则计算渠道佣金，无则查询pid的用户再计算佣金
						if($v['relation_id']){
							$u = pdo_get(MODULE_NAME."_user_u", array("relation_id" => $v['relation_id'], "system_id" => $settings['system_id']));
							//是不是默认的渠道pid下属rid
							if($u){
							}else{
								$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid_u")." where system_id = ".$settings['system_id']." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid = '".$v['relation_id']."' and is_use = 1 order by uid desc limit 1");
								if($pid){
									$u = pdo_get(MODULE_NAME."_user_u", array("user_id" => $pid[0]['uid'], "system_id" => $settings['system_id']));
								}
							}
						}else{
							$pid_r = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid_u")." where system_id = ".$settings['system_id']." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid != ''");
							if(!$pid_r){
								$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid_u")." where system_id = ".$settings['system_id']." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and is_use = 1 order by uid desc limit 1");
							}else{
								$r = 1;
							}
							if($pid){
								$u = pdo_get(MODULE_NAME."_user_u", array("user_id" => $pid[0]['uid'], "system_id" => $settings['system_id']));							
							}
						}
						
						if($u){
							$fee = fee($u['uid'],$id);
						}else{
							$fee = fee('000000',$id);
						}
						$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
						
						$order2 = pdo_get(MODULE_NAME."_order_u", array("order_id" => trim($v['trade_parent_id']), "system_id" => $settings['system_id']));
						if(!$order2 && !$r){
						  $resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => trim($v['trade_parent_id']) , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'], "new" => 1 , "system_id" => $settings['system_id'] 
							  , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_1_uid" => $fee['c_1_uid'] , "c1_uid" => $fee['c1_uid']
							  , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_2_uid" => $fee['c_2_uid'] 
							  , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_3_uid" => $fee['c_3_uid'] 
							  , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_t_uid" => $fee['c_t_uid'] 
							  , "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_2t_uid" => $fee['c_2t_uid'] 
							  , "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_1h_uid" => $fee['c_1h_uid'] 
							  , "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_2h_uid" => $fee['c_2h_uid'] 
							  , "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_3h_uid" => $fee['c_3h_uid'] 
							  , "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_4h_uid" => $fee['c_4h_uid']));
						  if($resin){
							  orderNotify($fee,$v,$settings['elm_yjrate'],$id,$settings['system_id'],$settings);
						  }
						  
						}
					}
				}else{
					$order = pdo_get(MODULE_NAME."_order", array("order_id" => trim($v['trade_parent_id']) , "uniacid" => $id));
					if($order){
						if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
						$fee = fee($order['c_1_uid'],$id);
						if($settings['errorcodeid'] == 93){
							var_dump($fee);
						}
						if($v['tk_status'] == 3){
							pdo_update(MODULE_NAME."_order", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "tk_earning_time" => strtotime($v['tk_earning_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "uniacid" => $id , "c_1" => round($v['pub_share_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
						}else{
							if($v['tk_status'] == 13){$v['pub_share_pre_fee'] = 0;}
							pdo_update(MODULE_NAME."_order", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "uniacid" => $id , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
						}
						
						
					}else{
						//是否有渠道id，有则计算渠道佣金，无则查询pid的用户再计算佣金
						if($v['relation_id']){
							$u = pdo_get(MODULE_NAME."_user", array("relation_id" => $v['relation_id'] , "uniacid" => $id));
							//是不是默认的渠道pid下属rid
							if($u){
							}else{
								$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid")." where uniacid = ".$id." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid = '".$v['relation_id']."' and is_use = 1 order by uid desc limit 1");
								if($pid){
									$u = pdo_get(MODULE_NAME."_user", array("user_id" => $pid[0]['uid'] , "uniacid" => $id));
								}
							}
						}else{
							$pid_r = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid")." where uniacid = ".$id." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid != ''");
							if(!$pid_r){
								$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid")." where uniacid = ".$id." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and is_use = 1 order by uid desc limit 1");
							}else{
								$r = 1;
							}
							if($pid){
								$u = pdo_get(MODULE_NAME."_user", array("user_id" => $pid[0]['uid'] , "uniacid" => $id));
							}
						}
						if($u){
							$fee = fee($u['uid'],$id);
						}else{
							$fee = fee('000000',$id);
						}
						$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
						if($settings['errorcodeid'] == 94){
							var_dump($fee);
						}
						$order2 = pdo_get(MODULE_NAME."_order", array("order_id" => trim($v['trade_parent_id']) , "uniacid" => $id));
						if(!$order2 && !$r){
						  $resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => trim($v['trade_parent_id']) , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "new" => 1, "uniacid" => $id 
							  , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_1_uid" => $fee['c_1_uid'] , "c1_uid" => $fee['c1_uid']
							  , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_2_uid" => $fee['c_2_uid'] 
							  , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_3_uid" => $fee['c_3_uid'] 
							  , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_t_uid" => $fee['c_t_uid'] 
							  , "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_2t_uid" => $fee['c_2t_uid'] 
							  , "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_1h_uid" => $fee['c_1h_uid'] 
							  , "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_2h_uid" => $fee['c_2h_uid'] 
							  , "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_3h_uid" => $fee['c_3h_uid'] 
							  , "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2) 
							  , "c_4h_uid" => $fee['c_4h_uid']));
						  if($resin){
						      orderNotify($fee,$v,$settings['elm_yjrate'],$id,$settings['system_id'],$settings);
						  }
						  
						}
					}
				}
				
			}
		}
		$page_no = 2;
		while($has_next){
			$res = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_dingdanchaxun2.ashx?appkey='.$settings['appkey'].'&sid='.$_GPC['sid'].'&start_time='.urlencode($start_time).'&end_time='.urlencode($end_time).'&signurl=2&position_index='.$position_index.'&	page_no='.$page_no),true);
			if($settings['errorcodeid'] == 95){
				var_dump($res);
			}
			$res = json_decode(file_get_contents($res['url']),true);
			$res_data1 = $res['tbk_sc_order_details_get_response']['data']['results']['publisher_order_dto'];
			$position_index = $res['tbk_sc_order_details_get_response']['data']['position_index'];
			$has_next = $res['tbk_sc_order_details_get_response']['data']['has_next'];
			if($res_data1){
				foreach ($res_data1 as $k => $v) {
					if(strpos($settings['pid_black'],$v['site_id'].'_'.$v['adzone_id']) !== false){ 
						continue;
					}
					if($v['order_type'] == '饿了么'){
						if($settings['system_type'] == 1){
							$order = pdo_get(MODULE_NAME."_order_u", array("order_id" => trim($v['trade_parent_id']), "system_id" => $settings['system_id']));
							if($order){
								if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
								$fee = fee($order['c_1_uid'],$id);
								if($settings['errorcodeid'] == 96){
									var_dump($fee);
								}
								if($v['tk_status'] == 3){
									pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "tk_earning_time" => strtotime($v['tk_earning_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'], "system_id" => $settings['system_id'] , "c_1" => round($v['pub_share_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "system_id" => $settings['system_id']));
								}else{
									if($v['tk_status'] == 13){$v['pub_share_pre_fee'] = 0;}
									pdo_update(MODULE_NAME."_order_u", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'], "system_id" => $settings['system_id'] , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "system_id" => $settings['system_id']));
								}
							}else{
								//是否有渠道id，有则计算渠道佣金，无则查询pid的用户再计算佣金
								if($v['relation_id']){
									$u = pdo_get(MODULE_NAME."_user_u", array("relation_id" => $v['relation_id'], "system_id" => $settings['system_id']));
									//是不是默认的渠道pid下属rid
									if($u){
										
									}else{
										$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid_u")." where system_id = ".$settings['system_id']." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid = '".$v['relation_id']."' and is_use = 1 order by uid desc limit 1");
										if($pid){
											$u = pdo_get(MODULE_NAME."_user_u", array("user_id" => $pid[0]['uid'], "system_id" => $settings['system_id']));
										}
									}
								}else{
									$pid_r = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid_u")." where system_id = ".$settings['system_id']." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid != ''");
									if(!$pid_r){
										$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid_u")." where system_id = ".$settings['system_id']." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and is_use = 1 order by uid desc limit 1");
									}else{
										$r = 1;
									}
									if($pid){
										$u = pdo_get(MODULE_NAME."_user_u", array("user_id" => $pid[0]['uid'], "system_id" => $settings['system_id']));							
									}
								}
								if($u){
									$fee = fee($u['uid'],$id);
								}else{
									$fee = fee('000000',$id);
								}
								$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
								$order2 = pdo_get(MODULE_NAME."_order_u", array("order_id" => trim($v['trade_parent_id']), "system_id" => $settings['system_id']));
								if(!$order2 && !$r){
								  $resin = pdo_insert(MODULE_NAME."_order_u", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => trim($v['trade_parent_id']) , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "new" => 1, "system_id" => $settings['system_id'] 
									  , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_1_uid" => $fee['c_1_uid'] , "c1_uid" => $fee['c1_uid']
									  , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_2_uid" => $fee['c_2_uid'] 
									  , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_3_uid" => $fee['c_3_uid'] 
									  , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_t_uid" => $fee['c_t_uid'] 
									  , "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_2t_uid" => $fee['c_2t_uid'] 
									  , "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_1h_uid" => $fee['c_1h_uid'] 
									  , "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_2h_uid" => $fee['c_2h_uid'] 
									  , "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_3h_uid" => $fee['c_3h_uid'] 
									  , "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_4h_uid" => $fee['c_4h_uid']));
								  if($resin){
								      orderNotify($fee,$v,$settings['elm_yjrate'],$id,$settings['system_id'],$settings);
								  }
								  
								}
							}
						}else{
							$order = pdo_get(MODULE_NAME."_order", array("order_id" => trim($v['trade_parent_id']) , "uniacid" => $id));
							if($order){
								if($order['c1_uid']){$order['c_1_uid'] = $order['c1_uid'];}
								$fee = fee($order['c_1_uid'],$id);
								if($v['tk_status'] == 3){
									pdo_update(MODULE_NAME."_order", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "tk_earning_time" => strtotime($v['tk_earning_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "uniacid" => $id , "c_1" => round($v['pub_share_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
								}else{
									if($v['tk_status'] == 13){$v['pub_share_pre_fee'] = 0;}
									pdo_update(MODULE_NAME."_order", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => $v['trade_parent_id'] , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "uniacid" => $id , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2), "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2), "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2), "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2), "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2), "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2), "c_1_uid" => $fee['c_1_uid'], "c_2_uid" => $fee['c_2_uid'], "c_3_uid" => $fee['c_3_uid'], "c_t_uid" => $fee['c_t_uid'], "c_2t_uid" => $fee['c_2t_uid'], "c_1h_uid" => $fee['c_1h_uid'] , "c_2h_uid" => $fee['c_2h_uid'] , "c_3h_uid" => $fee['c_3h_uid'] , "c_4h_uid" => $fee['c_4h_uid']) , array("id" => $order['id'] , "uniacid" => $id));
								}
								
							}else{
								//是否有渠道id，有则计算渠道佣金，无则查询pid的用户再计算佣金
								if($v['relation_id']){
									$u = pdo_get(MODULE_NAME."_user", array("relation_id" => $v['relation_id'] , "uniacid" => $id));
									//是不是默认的渠道pid下属rid
									if($u){
										
									}else{
										$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid")." where uniacid = ".$id." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid = '".$v['relation_id']."' and is_use = 1 order by uid desc limit 1");
										if($pid){
											$u = pdo_get(MODULE_NAME."_user", array("user_id" => $pid[0]['uid'] , "uniacid" => $id));
										}
									}
								}else{
									$pid_r = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid")." where uniacid = ".$id." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and rid != ''");
									if(!$pid_r){
										$pid = pdo_fetchall("SELECT * FROM ".tablename(MODULE_NAME."_pid")." where uniacid = ".$id." and pid like '%".$v['site_id']."_".$v['adzone_id']."%' and is_use = 1 order by uid desc limit 1");
									}else{
										$r = 1;
									}
									if($pid){
										$u = pdo_get(MODULE_NAME."_user", array("user_id" => $pid[0]['uid'] , "uniacid" => $id));
									}
								}
								if($u){
									$fee = fee($u['uid'],$id);
								}else{
									$fee = fee('000000',$id);
								}
								$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '新订单用户分佣',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($fee)));
								$order2 = pdo_get(MODULE_NAME."_order", array("order_id" => trim($v['trade_parent_id']) , "uniacid" => $id));
								if(!$order2 && !$r){
								  $resin = pdo_insert(MODULE_NAME."_order", array("pingtai" => 'elm' , "pingtai_name" => $v['order_type'] , "order_type" => $v['order_type'] , "order_id" => trim($v['trade_parent_id']) , "order_paid_time" => strtotime($v['tk_paid_time']) , "order_price" => $v['alipay_total_price'] , "order_profit" => $v['pub_share_pre_fee'] , "shopname" => $v['seller_shop_title'] , "goods_img" => $v['item_img'] , "goods_title" => $v['item_title'] , "adzone_id" => $v['adzone_id'] , "site_id" => $v['site_id'] , "relation_id" => $v['relation_id'] , "alimama_rate" => $v['alimama_rate'] , "income_rate" => $v['income_rate'] , "order_create_time" => strtotime($v['tk_create_time']) , "order_status" => $v['tk_status'] , "new" => 1, "uniacid" => $id 
									  , "c_1" => round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_1_uid" => $fee['c_1_uid'] , "c1_uid" => $fee['c1_uid']
									  , "c_2" => round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_2_uid" => $fee['c_2_uid'] 
									  , "c_3" => round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_3_uid" => $fee['c_3_uid'] 
									  , "c_t" => round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_t_uid" => $fee['c_t_uid'] 
									  , "c_2t" => round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_2t_uid" => $fee['c_2t_uid'] 
									  , "c_1h" => round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_1h_uid" => $fee['c_1h_uid'] 
									  , "c_2h" => round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_2h_uid" => $fee['c_2h_uid'] 
									  , "c_3h" => round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_3h_uid" => $fee['c_3h_uid'] 
									  , "c_4h" => round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $settings['elm_yjrate']/10000,2) 
									  , "c_4h_uid" => $fee['c_4h_uid']));
								  if($resin){
								      orderNotify($fee,$v,$settings['elm_yjrate'],$id,$settings['system_id'],$settings);
								  }
								  
								}
							}
						}
					}
				}
			}
			$page_no++;
		}
	}
	$stime += $addtime;
	$start_timeStamp += $addtime;
} while ($start_timeStamp<=$end_timeStamp);


function orderNotify($fee,$v,$yjrate,$id,$system_id,$settings){
	  if($fee['c_1_uid'] && round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_1_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_1_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_1_openid']));
							  $res = xcxneworderNotify($fee['c_1_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_1_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_1_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_1_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_2_uid'] && round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2_openid']));
							  $res = xcxneworderNotify($fee['c_2_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_3_uid'] && round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_3_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_3_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_3_openid']));
							  $res = xcxneworderNotify($fee['c_3_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_3_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_3_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_3_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_t_uid'] && round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_t_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_t_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_t_openid']));
							  $res = xcxneworderNotify($fee['c_t_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_t_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_t_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_t_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_t_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_2t_uid'] && round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2t_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2t_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2t_openid']));
							  $res = xcxneworderNotify($fee['c_2t_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2t_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2t_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2t_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2t_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_1h_uid'] && round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_1h_uid'], "system_id" => $system_id));
			  if($u){
				   $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_1h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_1h_openid']));
							  $res = xcxneworderNotify($fee['c_1h_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_1h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_1h_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_1h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_1h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_2h_uid'] && round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_2h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_2h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_2h_openid']));
							  $res = xcxneworderNotify($fee['c_2h_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_2h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_2h_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_2h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_2h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	  if($fee['c_3h_uid'] && round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_3h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_3h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_3h_openid']));
							  $res = xcxneworderNotify($fee['c_3h_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_3h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_3h_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_3h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_3h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
	   if($fee['c_4h_uid'] && round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $yjrate/10000,2)>0){
		  if($system_id > 0){
			  $u = pdo_get(MODULE_NAME."_user_u", array("uid" => $fee['c_4h_uid'], "system_id" => $system_id));
			  if($u){
				  $czgzh = pdo_fetch("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid = ".$settings['gzh_id']." limit 1");
				  if($czgzh){
					  neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$settings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
				  }else{
					  $czgzhall = pdo_fetchall("SELECT * FROM " . tablename("mc_mapping_fans") . " WHERE follow = 1 AND unionid = '".$u['unionid'] . "' AND uniacid in(SELECT uniacid FROM " . tablename("account_wechats") . ")");
					  $is_send = 0;
					  foreach ($czgzhall as $k => $vv) {
						  $appid = pdo_get("account_wechats", array("uniacid" => $vv['uniacid']));
					      $xcxset = pdo_fetch("SELECT * FROM " . tablename("uni_account_modules") . " WHERE module = '". MODULE_NAME . "' AND settings like '%".$appid['key']."%' limit 1");
						  if($xcxset){
							  $xcxsettings = unserialize($xcxset['settings']);
						      neworderNotify($czgzh['openid'], $v['trade_parent_id'], $v['item_title'],$xcxsettings,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['alipay_total_price'],$id);
							  $is_send = 1;
							  break;
						  }
					  }
					  if($is_send == 0){
						  if($fee['c_4h_s1'] > 0){
							  $xcxid = pdo_get(MODULE_NAME."_user", array("openid" => $fee['c_4h_openid']));
							  $res = xcxneworderNotify($fee['c_4h_openid'], $v['trade_parent_id'], $v['item_title'],$xcxid['uniacid'],$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
							  if($res){
								  $up = pdo_update(MODULE_NAME."_user_u", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
								  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("unionid" => $u['unionid'], "system_id" => $system_id,"s_1_num >" => 0));
							  }
						  }
					  }
				  }
			  }
		  }else{//发送小程序消息
			  if($fee['c_4h_s1'] > 0){
				  $res = xcxneworderNotify($fee['c_4h_openid'], $v['trade_parent_id'], $v['item_title'],$id,$v['tk_paid_time'],round($v['pub_share_pre_fee'] * $fee['c_4h_fee'] * $yjrate/10000,2),$v['alipay_total_price']);
				  if($res){
					  $up = pdo_update(MODULE_NAME."_user", array("s_1_num -=" => 1), array("openid" => $fee['c_4h_openid'],"s_1_num >" => 0));
				  }
			  }
		  }
	  }
}
function neworderNotify($openid, $order_id, $goods_title, $xcxsettings, $paytime, $fee, $price, $id)
{
	global $_GPC;
	global $_W;
	$config = $xcxsettings;
	load()->model('mc');
	$_W["account"] = uni_fetch($id);
	if (empty($_W["account"])) {
		exit("initial error hash or id");
	}
	$account_api = WeAccount::create();
	$token = $account_api->getAccessToken();
	$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=" . $token;
	$post = array();
	$post["touser"] = $openid;
	$order_id = cut_str($order_id, 4, 0).'****'.cut_str($order_id, 4, -4);
	$mp_template_msg = array("appid" => $config["gzh_appid"], "template_id" => $config["gzh_neworder_tplid"], "miniprogram" => array("appid" => $_W["account"]["key"], "pagepath" => "pages/user/index"), "data" => array("first" => array("value" => "又来新订单啦！", "color" => "#173177"), "keyword1" => array("value" => $goods_title, "color" => "#173177"), "keyword2" => array("value" => $paytime, "color" => "#173177"), "keyword3" => array("value" => '￥'.$price.' (预估:￥'.$fee.')', "color" => "#173177"), "keyword4" => array("value" => $order_id, "color" => "#173177"), "keyword5" => array("value" => "-", "color" => "#173177"), "remark" => array("value" => "点击本消息可以快速打开小程序。", "color" => "#173177")));
	$post["mp_template_msg"] = $mp_template_msg;
	$res = ihttp_request($url, json_encode($post));
	$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '公众号新订单通知',"apiname" => 'neworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($post).json_encode($res)));
	if($res['errcode'] == 0){
		return true;
	}else{
		return false;
	}
}

function xcxneworderNotify($openid, $order_id, $goods_title, $id, $paytime, $fee, $price)
{
	global $_GPC;
	global $_W;
	$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" =>$id));
	$config = unserialize($settings['settings']);
	load()->model('mc');
	if (!empty($id)) {
		$_W["account"] = uni_fetch($id);
	}
	if (empty($_W["account"])) {
		exit("initial error hash or id");
	}
	$account_api = WeAccount::create();
	$token = $account_api->getAccessToken();
	$url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$token;
	$dd = array();
	$order_id = cut_str($order_id, 4, 0).'****'.cut_str($order_id, 4, -4);
	$dd['touser'] = $openid;
	$dd['template_id'] = $config["warn_order_tplid"];
	$dd['page'] = 'pages/user/index';
	$dd['data'] = array(
		$config["warn_order_tplid_1"]=>array(
			"value"=>$order_id
		),
		$config["warn_order_tplid_2"]=>array(
			"value"=>$paytime
		),
		$config["warn_order_tplid_3"]=>array(
			"value"=>'￥'.$price
		),
		$config["warn_order_tplid_4"]=>array(
			"value"=>mb_substr($goods_title,0,20)
		)
	);
	load()->func('communication');
	$res = ihttp_request($url,json_encode($dd));
	$res = json_decode($res["content"],true);
	$log = pdo_insert(MODULE_NAME . "_systemlog", array("uniacid" => $id, "api_appKey" => '小程序新订单通知',"apiname" => 'xcxneworderNotify',"create_time" => $_W["timestamp"], "log" => json_encode($dd).json_encode($res)));
	if($res['errcode'] == 0){
		return true;
	}else{
		return false;
	}
	
}

function cut_str($string, $sublen, $start = 0, $code = 'UTF-8') 
{ 
	if($code == 'UTF-8') 
	{ 
		$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; 
		preg_match_all($pa, $string, $t_string);
		if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen));
		return join('', array_slice($t_string[0], $start, $sublen));
	}
	else
	{
		$start = $start*2;
		$sublen = $sublen*2;
		$strlen = strlen($string);
		$tmpstr = '';
		for($i=0; $i< $strlen; $i++)
		{
			if($i>=$start && $i< ($start+$sublen))
			{
				if(ord(substr($string, $i, 1))>129)
				{
					$tmpstr.= substr($string, $i, 2);
				}
				else
				{
					$tmpstr.= substr($string, $i, 1);
				}
			}
			if(ord(substr($string, $i, 1))>129) $i++;
		}
		return $tmpstr;
	}
}
function fee($uid,$id)
{
	global $_GPC;
	global $_W;
	$settings = pdo_get("uni_account_modules", array("module" => MODULE_NAME , "uniacid" =>$id));
	$settings = unserialize($settings['settings']);
	if($settings['system_type'] == 1){
		$u = pdo_get(MODULE_NAME."_user_u", array("uid" => $uid, "system_id" => $settings['system_id']));
	}else{
		$u = pdo_get(MODULE_NAME."_user", array("uid" => $uid , "uniacid" => $id));
	}
	if($u){
		//如果是普通会员
		$t = 0;$h = 0;$h1 = 0;$h2 = 0;$h3 = 0;$h4 = 0;
		if($u['is_tuan'] == 0){
			$c_1_uid = $u['uid'];
			$c_1_openid = $u['openid'];
			$c_1_s1 = $u['s_1_num'];
			$c_1_fee = $settings['c_1'];
			if($u['invite_uid'] != '0'){
				$fa_uid_array = array_reverse(explode("_",$u['invite_uid']));
				$i1 = 1;
				foreach($fa_uid_array as $v){
					if($settings['system_type'] == 1){
						$u1 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v , "system_id" => $settings['system_id']));
					}else{
						$u1 = pdo_get(MODULE_NAME."_user", array("uid" => $v , "uniacid" => $id));
					}
					if($u1['is_tuan'] == 0 && $i1 == 1){//如果是普通会员直推
						$c_2_uid = $u1['uid'];
						$c_2_openid = $u1['openid'];
						$c_2_s1 = $u1['s_1_num'];
						$c_2_fee = $settings['c_2'];
						$i2 = 1;
						foreach($fa_uid_array as $v2){
							if($settings['system_type'] == 1){
								$u2 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v2 , "system_id" => $settings['system_id']));
							}else{
								$u2 = pdo_get(MODULE_NAME."_user", array("uid" => $v2 , "uniacid" => $id));
							}
							if($u2['is_tuan'] == 0 && $i2 == 2){//如果是普通会员间推
								$c_3_uid = $u2['uid'];
								$c_3_openid = $u2['openid'];
								$c_3_s1 = $u2['s_1_num'];
								$c_3_fee = $settings['c_3'];
								$i3 = 1;
								foreach($fa_uid_array as $v3){
									if($settings['system_type'] == 1 && $i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v3 , "system_id" => $settings['system_id']));
									}elseif($i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user", array("uid" => $v3 , "uniacid" => $id));
									}
									if($u3['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0 && $i3 > 2){//团长非直属
										$c_t_uid = $u3['uid'];
										$c_t_openid = $u3['openid'];
										$c_t_s1 = $u3['s_1_num'];
										$c_t_fee = $settings['c_t'];
										$t = 1;
										continue;
									}elseif($u3['is_tuan'] == 1 && $t == 1 && $h == 0 && $h1 == 0  && $i3 > 2){//团长直属团长
										$c_2t_uid = $u3['uid'];
										$c_2t_openid = $u3['openid'];
										$c_2t_s1 = $u3['s_1_num'];
										$c_2t_fee = $settings['c_2t'];
										$t = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $t == 0 && $h == 0 && $h1 == 0 && $i3 > 2){//合伙人非直属会员
										$c_t_uid = $u3['uid'];
										$c_t_openid = $u3['openid'];
										$c_t_s1 = $u3['s_1_num'];
										$c_t_fee = $settings['c_h_3'];
										$h = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $t > 0 && $h == 0 && $h1 == 0 && $i3 > 2){//合伙人直属团队
										$c_1h_uid = $u3['uid'];
										$c_1h_openid = $u3['openid'];
										$c_1h_s1 = $u3['s_1_num'];
										$c_1h_fee = $settings['c_1h'];
										$h = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $t > 0 && $h == 1 && $h1 == 0 && $i3 > 2){//合伙人间属团队
										$c_2h_uid = $u3['uid'];
										$c_2h_openid = $u3['openid'];
										$c_2h_s1 = $u3['s_1_num'];
										$c_2h_fee = $settings['c_2h'];
										$h = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i3 > 2){//合伙人直属合伙人
										$c_3h_uid = $u3['uid'];
										$c_3h_openid = $u3['openid'];
										$c_3h_s1 = $u3['s_1_num'];
										$c_3h_fee = $settings['c_3h'];
										$h1 = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i3 > 2){//合伙人间属合伙人
										$c_4h_uid = $u3['uid'];
										$c_4h_openid = $u3['openid'];
										$c_4h_s1 = $u3['s_1_num'];
										$c_4h_fee = $settings['c_4h'];
										$h1 = 2;
										break;
									}
									$i3++;
								}
								break;
							}elseif($u2['is_tuan'] == 1 && $i2 == 2){//如果是团长间推
								$c_t_uid = $u2['uid'];
								$c_t_openid = $u2['openid'];
								$c_t_s1 = $u2['s_1_num'];
								$c_t_fee = $settings['c_t'];
								$i3 = 1;
								foreach($fa_uid_array as $v3){
									if($settings['system_type'] == 1 && $i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v3 , "system_id" => $settings['system_id']));
									}elseif($i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user", array("uid" => $v3 , "uniacid" => $id));
									}
									if($u3['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0  && $i3 > 2){//团长直属团长
										$c_2t_uid = $u3['uid'];
										$c_2t_openid = $u3['openid'];
										$c_2t_s1 = $u3['s_1_num'];
										$c_2t_fee = $settings['c_2t'];
										$t = 2;
										continue;
									}elseif($u3['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0  && $i3 > 2){//团长直属团长
										$c_1h_uid = $u3['uid'];
										$c_1h_openid = $u3['openid'];
										$c_1h_s1 = $u3['s_1_num'];
										$c_1h_fee = $settings['c_1h'];
										$h = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 0 && $h1 == 0 && $i3 > 2){//合伙人直属团队
										$c_1h_uid = $u3['uid'];
										$c_1h_openid = $u3['openid'];
										$c_1h_s1 = $u3['s_1_num'];
										$c_1h_fee = $settings['c_1h'];
										$h = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 1 && $h1 == 0 && $i3 > 2){//合伙人间属团队
										$c_2h_uid = $u3['uid'];
										$c_2h_openid = $u3['openid'];
										$c_2h_s1 = $u3['s_1_num'];
										$c_2h_fee = $settings['c_2h'];
										$h = 2;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i3 > 2){//合伙人直属合伙人
										$c_3h_uid = $u3['uid'];
										$c_3h_openid = $u3['openid'];
										$c_3h_s1 = $u3['s_1_num'];
										$c_3h_fee = $settings['c_3h'];
										$h1 = 1;
										continue;
									}elseif($u3['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i3 > 2){//合伙人间属合伙人
										$c_4h_uid = $u3['uid'];
										$c_4h_openid = $u3['openid'];
										$c_4h_s1 = $u3['s_1_num'];
										$c_4h_fee = $settings['c_4h'];
										$h1 = 2;
										break;
									}
									$i3++;
								}
								break;
							}elseif($u2['is_tuan'] == 2 && $i2 == 2){//如果是合伙人间推
								$c_t_uid = $u2['uid'];
								$c_t_openid = $u2['openid'];
								$c_t_s1 = $u2['s_1_num'];
								$c_t_fee = $settings['c_h_3'];
								$i3 = 1;
								foreach($fa_uid_array as $v3){
									if($settings['system_type'] == 1 && $i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v3 , "system_id" => $settings['system_id']));
									}elseif($i3 > 2){
										$u3 = pdo_get(MODULE_NAME."_user", array("uid" => $v3 , "uniacid" => $id));
									}
									if($u3['is_tuan'] == 2 && $h1 == 0 && $i3 > 2){//合伙人直属合伙人
										$c_3h_uid = $u3['uid'];
										$c_3h_openid = $u3['openid'];
										$c_3h_s1 = $u3['s_1_num'];
										$c_3h_fee = $settings['c_3h'];
										$h1 = 1;
										continue;;
									}
									if($u3['is_tuan'] == 2 && $h1 == 1 && $i3 > 2){//合伙人间属合伙人
										$c_4h_uid = $u3['uid'];
										$c_4h_openid = $u3['openid'];
										$c_4h_s1 = $u3['s_1_num'];
										$c_4h_fee = $settings['c_4h'];
										$h1 = 2;
										break;
									}
									$i3++;
								}
								break;
							}
							$i2++;
						}
						break;
					}elseif($u1['is_tuan'] == 1 && $i1 == 1){//如果是团长直推
						$c_2_uid = $u1['uid'];
						$c_2_openid = $u1['openid'];
						$c_2_s1 = $u1['s_1_num'];
						$c_2_fee = $settings['c_t_2'];
						$i2 = 1;
						foreach($fa_uid_array as $v2){
							if($settings['system_type'] == 1){
								$u2 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v2 , "system_id" => $settings['system_id']));
							}else{
								$u2 = pdo_get(MODULE_NAME."_user", array("uid" => $v2 , "uniacid" => $id));
							}
							if($u2['is_tuan'] == 1 && $t == 0  && $h == 0 && $h1 == 0 && $i2 > 1){//如果是团长间推
								$c_2t_uid = $u2['uid'];
								$c_2t_openid = $u2['openid'];
								$c_2t_s1 = $u2['s_1_num'];
								$c_2t_fee = $settings['c_2t'];
								$t = 2;
								continue;
							}elseif($u2['is_tuan'] == 2 && $t == 0  && $h == 0 && $h1 == 0 && $i2 > 1){//如果是团长间推
								$c_1h_uid = $u2['uid'];
								$c_1h_openid = $u2['openid'];
								$c_1h_s1 = $u2['s_1_num'];
								$c_1h_fee = $settings['c_1h'];
								$h = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 0 && $h1 == 0 && $i2 > 1){//合伙人直属团队
								$c_1h_uid = $u2['uid'];
								$c_1h_openid = $u2['openid'];
								$c_1h_s1 = $u2['s_1_num'];
								$c_1h_fee = $settings['c_1h'];
								$h = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 1 && $h1 == 0 && $i2 > 1){//合伙人间属团队
								$c_2h_uid = $u2['uid'];
								$c_2h_openid = $u2['openid'];
								$c_2h_s1 = $u2['s_1_num'];
								$c_2h_fee = $settings['c_2h'];
								$h = 2;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i2 > 1){//合伙人直属合伙人
								$c_3h_uid = $u2['uid'];
								$c_3h_openid = $u2['openid'];
								$c_3h_s1 = $u2['s_1_num'];
								$c_3h_fee = $settings['c_3h'];
								$h1 = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i2 > 1){//合伙人间属合伙人
								$c_4h_uid = $u2['uid'];
								$c_4h_openid = $u2['openid'];
								$c_4h_s1 = $u2['s_1_num'];
								$c_4h_fee = $settings['c_4h'];
								$h1 = 2;
								break;
							}
							$i2++;
						}
						break;
					}elseif($u1['is_tuan'] == 2 && $i1 == 1){//如果是合伙人直推
						$c_2_uid = $u1['uid'];
						$c_2_openid = $u1['openid'];
						$c_2_s1 = $u1['s_1_num'];
						$c_2_fee = $settings['c_h_2'];
						$i2 = 1;
						foreach($fa_uid_array as $v2){
							if($settings['system_type'] == 1 && $i2 > 1){
								$u2 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v2 , "system_id" => $settings['system_id']));
							}elseif($i2 > 1){
								$u2 = pdo_get(MODULE_NAME."_user", array("uid" => $v2 , "uniacid" => $id));
							}
							if($u2['is_tuan'] == 2 && $h1 == 0 && $i2 > 1){//合伙人直属合伙人
								$c_3h_uid = $u2['uid'];
								$c_3h_openid = $u2['openid'];
								$c_3h_s1 = $u2['s_1_num'];
								$c_3h_fee = $settings['c_3h'];
								$h1 = 1;
								continue;
							}elseif($u2['is_tuan'] == 2 && $h1 == 1 && $i2 > 1){//合伙人间属合伙人
								$c_4h_uid = $u2['uid'];
								$c_4h_openid = $u2['openid'];
								$c_4h_s1 = $u2['s_1_num'];
								$c_4h_fee = $settings['c_4h'];
								$h1 = 2;
								break;
							}
							$i2++;
						}
						break;
					}
					$i1++;
				}
			}
		}elseif($u['is_tuan'] == 1){//如果是团长
			$c_1_uid = $u['uid'];
			$c_1_openid = $u['openid'];
			$c_1_s1 = $u['s_1_num'];
			$c_1_fee = $settings['c_t_1'];
			if($u['invite_uid'] != '0'){
				$fa_uid_array = array_reverse(explode("_",$u['invite_uid']));
				$i1 = 1;
				foreach($fa_uid_array as $v){
					if($settings['system_type'] == 1){
						$u1 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v , "system_id" => $settings['system_id']));
					}else{
						$u1 = pdo_get(MODULE_NAME."_user", array("uid" => $v , "uniacid" => $id));
					}
					if($u1['is_tuan'] == 1 && $t == 0 && $h == 0 && $h1 == 0 && $i1 == 1){//如果是团长直推
						$c_2t_uid = $u1['uid'];
						$c_2t_openid = $u1['openid'];
						$c_2t_s1 = $u1['s_1_num'];
						$c_2t_fee = $settings['c_2t'];
						$t = 2;
						continue;
					}elseif($u1['is_tuan'] == 2 && $t == 0 && $h == 0 && $h1 == 0 && $i1 == 1){//如果是合伙人直推
						$c_1h_uid = $u1['uid'];
						$c_1h_openid = $u1['openid'];
						$c_1h_s1 = $u1['s_1_num'];
						$c_1h_fee = $settings['c_1h'];
						$h = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 0 && $h1 == 0 && $i1 > 1){//合伙人直属团队
						$c_1h_uid = $u1['uid'];
						$c_1h_openid = $u1['openid'];
						$c_1h_s1 = $u1['s_1_num'];
						$c_1h_fee = $settings['c_1h'];
						$h = 1;
						echo $c_1h_uid;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 1 && $h1 == 0 && $i1 > 1){//合伙人间属团队
						$c_2h_uid = $u1['uid'];
						$c_2h_openid = $u1['openid'];
						$c_2h_s1 = $u1['s_1_num'];
						$c_2h_fee = $settings['c_2h'];
						$h = 2;
						echo $c_2h_uid;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 2 && $h1 == 0 && $i1 > 1){//合伙人直属合伙人
						$c_3h_uid = $u1['uid'];
						$c_3h_openid = $u1['openid'];
						$c_3h_s1 = $u1['s_1_num'];
						$c_3h_fee = $settings['c_3h'];
						$h1 = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h == 2 && $h1 == 1 && $i1 > 1){//合伙人间属合伙人
						$c_4h_uid = $u1['uid'];
						$c_4h_openid = $u1['openid'];
						$c_4h_s1 = $u1['s_1_num'];
						$c_4h_fee = $settings['c_4h'];
						$h1 = 2;
						break;
					}
					$i1++;
				}
			}
		}elseif($u['is_tuan'] == 2){//如果是合伙人
			$c_1_uid = $u['uid'];
			$c_1_openid = $u['openid'];
			$c_1_s1 = $u['s_1_num'];
			$c_1_fee = $settings['c_h_1'];
			if($u['invite_uid'] != '0'){
				$fa_uid_array = array_reverse(explode("_",$u['invite_uid']));
				$i1 = 1;
				foreach($fa_uid_array as $v){
					if($settings['system_type'] == 1){
						$u1 = pdo_get(MODULE_NAME."_user_u", array("uid" => $v , "system_id" => $settings['system_id']));
					}else{
						$u1 = pdo_get(MODULE_NAME."_user", array("uid" => $v , "uniacid" => $id));
					}
					if($u1['is_tuan'] == 2 && $h1 == 0 && $i1 > 0){//合伙人直属合伙人
						$c_3h_uid = $u1['uid'];
						$c_3h_openid = $u1['openid'];
						$c_3h_s1 = $u1['s_1_num'];
						$c_3h_fee = $settings['c_3h'];
						$h1 = 1;
						continue;
					}elseif($u1['is_tuan'] == 2 && $h1 == 1 && $i1 > 0){//合伙人间属合伙人
						$c_4h_uid = $u1['uid'];
						$c_4h_openid = $u1['openid'];
						$c_4h_s1 = $u1['s_1_num'];
						$c_4h_fee = $settings['c_4h'];
						$h1 = 2;
						break;
					}
					$i1++;
				}
			}
		}
	}
	$c1_uid = $c_1_uid;
	if(!$c_1_uid || !$c_1_fee){
		$c_1_uid = 0;
		$c_1_openid = '';
		$c_1_s1 = 0;
		$c_1_fee = 0;
	}
	if(!$c_2_uid || !$c_2_fee){
		$c_2_uid = 0;
		$c_2_openid = '';
		$c_2_s1 = 0;
		$c_2_fee = 0;
	}
	if(!$c_3_uid || !$c_3_fee){
		$c_3_uid = 0;
		$c_3_openid = '';
		$c_3_s1 = 0;
		$c_3_fee = 0;
	}
	if(!$c_t_uid || !$c_t_fee){
		$c_t_uid = 0;
		$c_t_openid = '';
		$c_t_s1 = 0;
		$c_t_fee = 0;
	}
	if(!$c_2t_uid || !$c_2t_fee){
		$c_2t_uid = 0;
		$c_2t_openid = '';
		$c_2t_s1 = 0;
		$c_2t_fee = 0;
	}
	if(!$c_1h_uid || !$c_1h_fee){
		$c_1h_uid = 0;
		$c_1h_openid = '';
		$c_1h_s1 = 0;
		$c_1h_fee = 0;
	}
	if(!$c_2h_uid || !$c_2h_fee){
		$c_2h_uid = 0;
		$c_2h_openid = '';
		$c_2h_s1 = 0;
		$c_2h_fee = 0;
	}
	if(!$c_3h_uid || !$c_3h_fee){
		$c_3h_uid = 0;
		$c_3h_openid = '';
		$c_3h_s1 = 0;
		$c_3h_fee = 0;
	}
	if(!$c_4h_uid || !$c_4h_fee){
		$c_4h_uid = 0;
		$c_4h_openid = '';
		$c_4h_s1 = 0;
		$c_4h_fee = 0;
	}
	$fee = array(
		'c1_uid' => $c1_uid,
		'c_1_uid' => $c_1_uid,
		'c_1_openid' => $c_1_openid,
		'c_1_s1' => $c_1_s1,
		'c_1_fee' => $c_1_fee,
		'c_2_uid' => $c_2_uid,
		'c_2_openid' => $c_2_openid,
		'c_2_s1' => $c_2_s1,
		'c_2_fee' => $c_2_fee,
		'c_3_uid' => $c_3_uid,
		'c_3_openid' => $c_3_openid,
		'c_3_s1' => $c_3_s1,
		'c_3_fee' => $c_3_fee,
		'c_t_uid' => $c_t_uid,
		'c_t_openid' => $c_t_openid,
		'c_t_s1' => $c_t_s1,
		'c_t_fee' => $c_t_fee,
		'c_2t_uid' => $c_2t_uid,
		'c_2t_openid' => $c_2t_openid,
		'c_2t_s1' => $c_2t_s1,
		'c_2t_fee' => $c_2t_fee,
		'c_1h_uid' => $c_1h_uid,
		'c_1h_openid' => $c_1h_openid,
		'c_1h_s1' => $c_1h_s1,
		'c_1h_fee' => $c_1h_fee,
		'c_2h_uid' => $c_2h_uid,
		'c_2h_openid' => $c_2h_openid,
		'c_2h_s1' => $c_2h_s1,
		'c_2h_fee' => $c_2h_fee,
		'c_3h_uid' => $c_3h_uid,
		'c_3h_openid' => $c_3h_openid,
		'c_3h_s1' => $c_3h_s1,
		'c_3h_fee' => $c_3h_fee,
		'c_4h_uid' => $c_4h_uid,
		'c_4h_openid' => $c_4h_openid,
		'c_4h_s1' => $c_4h_s1,
		'c_4h_fee' => $c_4h_fee
	);
	return $fee;
	
}